home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / contrib / multimedia / mmencode.c < prev    next >
C/C++ Source or Header  |  1993-03-17  |  2KB  |  64 lines

  1. /* cc -o mmencode codes.c mmencode.c */
  2. /*
  3. Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  4.  
  5. Permission to use, copy, modify, and distribute this material 
  6. for any purpose and without fee is hereby granted, provided 
  7. that the above copyright notice and this permission notice 
  8. appear in all copies, and that the name of Bellcore not be 
  9. used in advertising or publicity pertaining to this 
  10. material without the specific, prior written permission 
  11. of an authorized representative of Bellcore.  BELLCORE 
  12. MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  13. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  14. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  15. */
  16. #include <stdio.h>
  17.  
  18. #define BASE64 1
  19. #define QP 2 /* quoted-printable */
  20.  
  21. main(argc, argv)
  22. int argc;
  23. char **argv;
  24. {
  25.     int encode = 1, which = BASE64, i, portablenewlines = 0;
  26.     FILE *fp = stdin;
  27.  
  28.     for (i=1; i<argc; ++i) {
  29.         if (argv[i][0] == '-') {
  30.             switch (argv[i][1]) {
  31.                 case 'u':
  32.                     encode = 0;
  33.                     break;
  34.                 case 'q':
  35.                     which = QP;
  36.                     break;
  37.                 case 'p':
  38.                     portablenewlines = 1;
  39.                     break;
  40.                 case 'b':
  41.                     which = BASE64;
  42.                     break;
  43.         default:
  44.                     fprintf(stderr,
  45.                        "Usage: mmencode [-u] [-q] [-b] [-p] [file name]\n");
  46.                     exit(-1);
  47.             }
  48.         } else {
  49.             fp = fopen(argv[i], "r");
  50.             if (!fp) {
  51.                 perror(argv[i]);
  52.                 exit(-1);
  53.             }
  54.         }
  55.     }
  56.     if (which == BASE64) {
  57.         if (encode) to64(fp, stdout, portablenewlines); else from64(fp, stdout, NULL, 0, portablenewlines);
  58.     } else {
  59.         if (encode) toqp(fp, stdout); else fromqp(fp, stdout, NULL, 0);
  60.     }
  61.     return(0);
  62. }
  63.  
  64.